<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSystemUsers extends \App\Utils\CreateMigration
{
    function columns(Blueprint $table)
    {
        $table->string('group_code', 50)->default('')->comment('所属用户组');
        $table->unsignedBigInteger('role_id')->default(0)->comment('角色ID');
        $table->string('username', 100)->default('')->comment('用户名');
        $table->string("mobile", 50)->default('')->comment("手机号");
        $table->string("email")->default('')->comment("邮箱");
        $table->string('password', 50)->default('')->comment('密码');
        $table->unsignedTinyInteger('status')->default(1)->comment('状态 1,正常 @system_user_status');
        $table->string('salt', 4)->nullable()->comment('密码盐');
        $table->longText("hospital_ids")->nullable()->comment("所属医院,多个用逗号分隔");
        $table->unsignedBigInteger("department_id")->default(0)->comment("所属部门");
        $table->string("avatar")->default(0)->comment("头像");
        $table->string("name")->default('')->comment("姓名");
        $table->index(['role_id'], 'idx_role_id');
        $table->index(['group_code'], 'idx_group_code');
        $table->unique(['username', 'deleted_at'], 'uk_username');
    }

    function tableInfo()
    {
        return ['system__users', '系统-用户表'];
    }

    function getData()
    {
        $salt = \Illuminate\Support\Str::random(4);
        $date = date('Y-m-d H:i:s');
        return [
            [
                'id' => 1,
                'username' => 'admin',
                'password' => md5(md5('123456') . $salt),
                'salt' => $salt,
                'mobile' => '12345678910',
                'email' => 'admin@9ey.com',
                'role_id' => 1,
                'group_code' => \App\Models\System\Group::PLAT,
                'status' => 1,
                'created_at' => $date,
                'updated_at' => $date,
            ]
        ];
    }
}
